package com.ydzt.fanka.server.init;

import org.apache.log4j.Logger;

import com.ydzt.fanka.server.space.broadcast.BroadCastServer;
import com.ydzt.fanka.server.space.bufferreceiver.BufferReceiverServer;
import com.ydzt.fanka.server.space.errorhanding.ErrServer;
import com.ydzt.fanka.server.space.socketreceiver.SocketReceiverServer;
import com.ydzt.fanka.server.space.transmit.SendTransmitServer;
import com.ydzt.fanka.server.space.transmit.TransmitListenrServer;
import com.ydzt.fanka.server.zwcl.ZwclUpdateAccountServer;

public class ThreadObjectPool {
	
	public static TransmitListenrServer transmitListenrServer = new TransmitListenrServer();
	public static SendTransmitServer sendTransmitServer = new SendTransmitServer();
	public static BufferReceiverServer bufferReceiverServer = new BufferReceiverServer();
	public static BroadCastServer broadCastServer = new BroadCastServer();
	public static SocketReceiverServer socketReceiverServer = new SocketReceiverServer();
	public static ErrServer errServer = new ErrServer();
	public static ZwclUpdateAccountServer zwclUpdateAccountServer = new ZwclUpdateAccountServer();
	
	public ThreadObjectPool(){
		/*
		transmitListenrServer = new TransmitListenrServer();
		sendTransmitServer = new SendTransmitServer();
		bufferReceiverServer = new BufferReceiverServer();
		broadCastServer = new BroadCastServer();
		socketReceiverServer = new SocketReceiverServer();
		errServer = new ErrServer();
		zwclUpdateAccountServer = new ZwclUpdateAccountServer();
		*/
		transmitListenrServer.setName("transmitThread");
		sendTransmitServer.setName("sendTransmitThread");
		bufferReceiverServer.setName("broadCastThread");
		socketReceiverServer.setName("socketReceiverThread");
		errServer.setName("errThread");
		zwclUpdateAccountServer.setName("zwclUpdateAccountThread");
	}
	
	static Logger logger = Logger.getLogger(ThreadObjectPool.class.getName());
	
	
	
	public static boolean TransmitListenrServerState;
	public static boolean SendTransmitServerState;
	public static boolean BufferReceiverServerState;
	public static boolean BroadCastServerState;
	public static boolean SocketReceiverServerState;
	public static boolean ErrServerState;
	public static boolean ZwclUpdateAccountServerState;
	
	@SuppressWarnings("deprecation")
	public static boolean waitBufferReceiverServer(){
		boolean flag = false;
		logger.info("进行wait时bufferReceiverServer的线程状态为:" + bufferReceiverServer.getState().toString());
		if(bufferReceiverServer.getState() == Thread.State.RUNNABLE){
			bufferReceiverServer.suspend();
			flag = true;
		}
		else{
			logger.info("bufferReceiverServer未wait");
		}
		return flag;
	}
	
	@SuppressWarnings("deprecation")
	public static boolean notifyBufferReceiverServer(){
		boolean flag = false;
		logger.info("进行run时bufferReceiverServer的线程状态为:" + bufferReceiverServer.getState().toString());
		if(bufferReceiverServer.getState() == Thread.State.RUNNABLE){
			bufferReceiverServer.resume();
			logger.info("bufferReceiverServer已经run");
			flag = true;
		}
		else if(bufferReceiverServer.getState() == Thread.State.TERMINATED){
			bufferReceiverServer.start();
			flag = true;
		}
		else if(bufferReceiverServer.getState() == Thread.State.WAITING){
			bufferReceiverServer.notify();
			flag = true;
		}
		else{
			logger.info("bufferReceiverServer未run");
		}
		return flag;
	}
}
